//
//  SecondViewController.m
//  Demo
//
//  Created by Echo on 13-9-24.
//

#import "AppDownViewController.h"


@interface AppDownViewController ()

@end

@implementation AppDownViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)cancel{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
    self.title = STR(@"APP下载链接");
    if ([Global curLanguageEn]) {
        self.title = @"APP Download Link";
    }
    [super viewDidLoad];

    UIBarButtonItem *leftItem = [UIBarButtonItem backImageBarButtonItem:[UIImage imageNamed:@"back.png"] target:self action:@selector(cancel)];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIImage *image = IMG(@"APP_link.png");
    image = IMG(@"qrcode.png");
    UIImageView *logo = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth-image.size.width/2)/2, 50, image.size.width/2, image.size.height/2)];
    logo.image = image;
    [self.view addSubview:logo];
    
    for (int i = 0; i < 2; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((kScreenWidth-197)/2, 250+i*50, 197, 24)];
        btn.titleLabel.font = [UIFont systemFontOfSize:15];
        btn.tag = i;
        if (i == 0) {
            [btn setTitle:STR(@"短信分享链接") forState:UIControlStateNormal];
            if ([Global curLanguageEn]) {
                [btn setTitle:@"Message To Share The Link" forState:UIControlStateNormal];
            }
        }else{
            [btn setTitle:STR(@"邮件分享链接") forState:UIControlStateNormal];
            if ([Global curLanguageEn]) {
                [btn setTitle:@"Email To Share The Link" forState:UIControlStateNormal];
            }
        }
        [btn setBackgroundImage:IMG(@"APP_link_btn.png") forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
}
-(void)btnPressed:(UIButton*)btn{
    if (btn.tag == 0) {
        MFMessageComposeViewController *sendMsgViewController=[[MFMessageComposeViewController alloc] init];
        if (sendMsgViewController) {
            sendMsgViewController.messageComposeDelegate = self;
            //NSArray *receivers = [NSArray arrayWithObject:];
            //sendMsgViewController.recipients = receivers;
            [self presentModalViewController:sendMsgViewController animated:YES];
        }
    }else{
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
    }
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
	[self dismissModalViewControllerAnimated:YES];
}
@end
